Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

inquirer-autocomplete-prompt

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inquirer-autocomplete-prompt

Autocomplete prompt for inquirer

  • 1.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2M
increased by4.25%
Maintainers
2
Weekly downloads
 
Created

What is inquirer-autocomplete-prompt?

The inquirer-autocomplete-prompt npm package is an extension for the Inquirer.js library that provides an autocomplete prompt. It allows users to search and select from a list of options dynamically, which is particularly useful for large datasets or when the list of options is not known beforehand.

What are inquirer-autocomplete-prompt's main functionalities?

Basic Autocomplete Prompt

This feature allows users to search and select from a list of options dynamically. The code sample demonstrates a basic autocomplete prompt where users can type to filter through a list of fruits.

const inquirer = require('inquirer');
const autocompletePrompt = require('inquirer-autocomplete-prompt');

inquirer.registerPrompt('autocomplete', autocompletePrompt);

const questions = [
  {
    type: 'autocomplete',
    name: 'fruit',
    message: 'What is your favorite fruit?',
    source: function(answersSoFar, input) {
      input = input || '';
      return new Promise(function(resolve) {
        setTimeout(function() {
          const fruits = ['Apple', 'Orange', 'Banana', 'Kiwi', 'Mango'];
          const filtered = fruits.filter(fruit => fruit.toLowerCase().includes(input.toLowerCase()));
          resolve(filtered);
        }, 100);
      });
    }
  }
];

inquirer.prompt(questions).then(answers => {
  console.log('Your favorite fruit:', answers.fruit);
});

Dynamic Data Source

This feature allows the autocomplete prompt to fetch data from an external source dynamically. The code sample demonstrates how to use the GitHub API to search for repositories based on user input.

const inquirer = require('inquirer');
const autocompletePrompt = require('inquirer-autocomplete-prompt');
const axios = require('axios');

inquirer.registerPrompt('autocomplete', autocompletePrompt);

const questions = [
  {
    type: 'autocomplete',
    name: 'repository',
    message: 'Select a GitHub repository:',
    source: async function(answersSoFar, input) {
      input = input || '';
      const response = await axios.get(`https://api.github.com/search/repositories?q=${input}`);
      return response.data.items.map(repo => repo.full_name);
    }
  }
];

inquirer.prompt(questions).then(answers => {
  console.log('Selected repository:', answers.repository);
});

Other packages similar to inquirer-autocomplete-prompt

FAQs

Package last updated on 19 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc